package hydrap2p.librarycli;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import hydrap2p.helper.ServiceConnector;
import hydrap2p.library.InvalidUID;
import hydrap2p.library.Library;
import hydrap2p.library.SharedItemInfo;

public class Browser {
	private static final long MAXUID=1000;
	public static void main(String[] args)
	{
		new Browser().run();
	}
	private Library.Iface library;
	
	public Browser()
	{
		library=ServiceConnector.getLibrary();			
	}
	
	public void run()
	{
		if (library==null)
		{
			System.out.println("Could not connect to the Library");
			return;
		}
		boolean running=true;
		BufferedReader inputreader=new BufferedReader(new InputStreamReader(System.in));
		while (running)
		{
			for (long index = 0; index<=MAXUID; index++)
			{
				try {
					SharedItemInfo item = library.getSharedItemInfo(index);
					if (item!=null)
						printSharedItemInfo(item);
				} catch (InvalidUID e) {	
				} catch (Exception e) {
					return;
				}
			}
			
			
			String input="";
			try {
				input=inputreader.readLine();
			} catch (IOException e) {
				return;
			}
		}
	}
		
	public void printSharedItemInfo(SharedItemInfo item)
	{
		System.out.println(item.uid+") "+item.pathname+"\\"+item.name+" "+item.size);
	}
		
}
